/*
 * @Author: zhangyang
 * @Date: 2022-02-28 17:19:35
 * @LastEditTime: 2022-06-12 15:41:24
 * @Description: vite 配置文件
 */
import { fileURLToPath, URL } from 'url';

import { defineConfig, loadEnv } from 'vite';
import type { ConfigEnv, UserConfigExport } from 'vite';
import vue from '@vitejs/plugin-vue';
import Unocss from 'unocss/vite';
// 自动导入
import AutoImport from 'unplugin-auto-import/vite';
import AutoComopnents from 'unplugin-vue-components/vite';

// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  const root = process.cwd();
  const viteEnv = loadEnv(mode, root);
  console.log("🚀 ~ file: vite.config.ts ~ line 36 ~ viteEnv", viteEnv);
  return defineConfig({
    base: './',
    plugins: [
      vue(),
      AutoComopnents({
        dirs: ['src/components'],
        dts: './src/auto-components.d.ts',
        include: [/\.vue$/, /\.tsx$/],
      }),
      AutoImport({
        dts: './src/auto-imports.d.ts',
        imports: ['vue', '@vueuse/core'],
      }),
      Unocss(),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
  });
}
